﻿
////////////////////////////////////////////////////////////////////////////////////////////
// 文件名: ETL_Source_ViewConfigBLL.gen.cs
//
// 模块名称: ETLSourceViewBll
//
// 作者: LPC
//
// 历史记录（记录修改记录，修改文件后请添加修改记录，注明修改时间、修改人，修改内容）:
// 13-2-5    LPC    创建文件
////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Common;
using DAL;
using Model;

namespace BLL
{
    /// <summary>
    /// ETL_Source_ViewConfig表业务逻辑层
    /// </summary>
    public class EtlSourceViewConfigBLL : BaseBLL
    {

        const string ErrorCodeSelect = "";    //查询异常编码
        const string ErrorCodeInsert = "";    //添加异常编码
        const string ErrorCodeUpdate = "";    //修改异常编码
        const string ErrorCodeDelete = "";    //删除异常编码

        public EtlSourceViewConfigBLL(LoginInfo info)
        {
            loginInfo = info;
        }
        /// <summary>
        /// 创建BLL对象
        /// </summary>
        /// <summary>
        /// 根据GUID字段获取ETL_Source_ViewConfigInfo实体对象
        /// </summary>
        /// <param name="guid">GUID</param>
        /// <returns>ETL_Source_ViewConfigInfo实体对象</returns>
        public ETL_Source_ViewConfigInfo GetInfoById(string guid)
        {
            try
            {
                EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
                return dal.GetInfoById(guid);
            }
            catch (Exception ex)
            { 
                throw ex;
            }
        }

        /// <summary>
        /// 往ETL_Source_ViewConfig表内添加新记录
        /// </summary>
        /// <returns>添加记录索引值</returns>
        public int Insert(IDataParameter[] eTLSourceViewConfigInfo)
        {
            try
            {
                EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
                int identity = dal.Insert(eTLSourceViewConfigInfo);
                return identity;
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Source_ViewConfigBLL", "Insert", AppError.EROR, 0, ex, "添加ETLSourceViewBll信息出错。", null);
                throw new SystemException(ErrorCodeInsert, ex);
            }
        }

        /// <summary>
        /// 更新ETL_Source_ViewConfig表记录
        /// </summary>
        public void Update(ETL_Source_ViewConfigInfo eTLSourceViewConfigInfo)
        {
            try
            {
                EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
                dal.Update(eTLSourceViewConfigInfo);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Source_ViewConfigBLL", "Update", AppError.EROR, 0, ex, "更新ETLSourceViewBll信息出错。",
                                String.Format("GUID = {0}", eTLSourceViewConfigInfo.Guid));
                throw new SystemException(ErrorCodeUpdate, ex);
            }
        }

        ///// <summary>
        ///// 根据GUID字段获取ETL_Source_ViewConfigInfo实体对象
        ///// </summary>
        ///// <param name="guid">GUID</param>
        //public void DeleteView(SqlParameter[] guid)
        //{
        //    try
        //    {
        //        EtlSourceViewConfigDAL.DeleteView(guid);
        //    }
        //    catch(Exception ex)
        //    {
        //        Logger.LogError("ETL_Source_ViewConfigBLL", "Delete", AppError.EROR, 0, ex, "删除ETLSourceViewBll信息出错。", 
        //                        String.Format("guid = {0}", guid));
        //        throw new SystemException(ErrorCodeDelete, ex);
        //    }
        //}


        /// <summary>
        /// 根据GUID字段获取ETL_Source_ViewConfigInfo实体对象
        /// </summary>
        /// <returns>List<ETL_Source_ViewConfigInfo/>实体对象</returns>
        public List<ETL_Source_ViewConfigInfo> GetList(IDataParameter[] par)
        {
            try
            {
                EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
                return dal.GetList(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Source_ViewConfigBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLSourceViewBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        /// <summary>
        /// 根据GUID字段获取ETL_Source_ViewConfigInfo实体对象
        /// </summary>
        /// <returns>List<ETL_Source_ViewConfigInfo/>实体对象</returns>
        public int GetListCount(IDataParameter[] par)
        {
            try
            {
                EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
                return dal.GetListCount(par);
            }
            catch (Exception ex)
            {
                Logger.LogError("ETL_Source_ViewConfigBLL", "GetInfo", AppError.EROR, 0, ex, "获取ETLSourceViewBll信息出错。",
                                "");
                throw new SystemException(ErrorCodeSelect, ex);
            }
        }

        public int CreateStgTB(IDataParameter[] paras)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.CreateStgTB(paras);
        }

        public void RollBack(string id)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            dal.RollBack(id);
        }

        public void DeleteView(SqlParameter[] viewConfigDelePar)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            dal.DeleteView(viewConfigDelePar);
        }

        public int AutoConfigModel(string viewName)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.AutoConfigModel(viewName);
        }
        public List<BigDataSouceViewInit> GetAllInit(string viewID)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.GetAllInit(viewID);
        }
        public IncrementRole GetIncrementRole(string viewID)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.GetIncrementRole(viewID);
        }
        public int AddInitBigData(SqlParameter[] para)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.AddInitBigData(para);
        }
        public int DeleteInitBigData(string viewID)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.DeleteInitBigData(viewID);
        }

        public List<ETL_Source_ViewConfigInfo> GetViewById(SqlParameter[] par)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.GetViewById(par);
        }

        public string GetSqlTypeName(string typeName, string connType)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.GetSqlTypeName(typeName, connType);
        }

        #region ETL_Source_ViewConfig
        public int DeleteSourceViewConfig(string guid)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.DeleteSourceViewConfig(guid);
        }
        /// <summary>
        /// 删除配置的源系统的表信息及其对应的字段信息
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public int DeleteSourceViewAndColumnConfig(string guid)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.DeleteSourceViewAndColumnConfig(guid);
        }

        /// <summary>
        /// 往ETL_Source_ViewConfig表内添加新记录
        /// </summary>
        /// <returns>添加记录索引值</returns>
        public int InsertSourceViewConfig(ETL_Source_ViewConfigInfo sourceViewConfigInfo)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.InsertSourceViewConfig(sourceViewConfigInfo);
        }
        public int AddBigDateTagConfig(string viewID,string sysID)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.AddBigDateTagConfig(viewID,sysID);
        }

        public int UpdateSourceViewConfig(ETL_Source_ViewConfigInfo sourceViewConfigInfo)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.UpdateSourceViewConfig(sourceViewConfigInfo);
        }

        public int UpdateIncrementRole(IncrementRole irole)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.UpdateIncrementRole(irole);
        }
        public ETL_Source_ViewConfigInfo GetSourceViewConfigInfoByGuid(string guid)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.GetSourceViewConfigInfoByGuid(guid);
        }

        public ETL_Source_ViewConfigInfo GetSourceViewConfigInfoByViewName(string id, string viewName)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.GetSourceViewConfigInfoByViewName(id, viewName);
        }

        public ETL_Task_List_History GetStepStatus(string id)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.GetStepStatus(id);
        }
        public List<ETL_Source_ViewConfigInfo> GetViewConfigById(string sourceSystemID , string sort, string order , int pageIndex, int pageSize, out int recordCount)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            var list = dal.GetViewConfigById(sourceSystemID , sort, order , pageIndex, pageSize, out  recordCount);
            EtlSourceViewColumnConfigDAL sourceViewColumnConfigDAL = new EtlSourceViewColumnConfigDAL(loginInfo);

            foreach (var sourceViewConfigInfo in list)
            {
                sourceViewConfigInfo.ColumnCount = sourceViewColumnConfigDAL.GetSourceViewColumnConfigCountBySystemID(sourceViewConfigInfo.Guid);
            }
            return list;
        }

        public bool IsExistByDisplayNameWithOutGUID(string guid, string displayName)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            var list = dal.GetByDisplayNameWithOutGUID(guid, displayName);
            if (list == null || list.Count == 0)
                return false;
            return true;
        }

        public bool IsExistByBigDataTag(string viewID,string tag)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.IsExistByBigDataTag(viewID,tag); ;
        }
        #endregion

        #region 公共存储过程单元

        public int CreateStgTB(string viewID)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.CreateStgTB(viewID);
        }
        #endregion

        #region 非存储过程单元

        public int RollBackSourceViewConfig(string viewID, bool deleteSourceViewConfig = true)
        {
            EtlSourceViewConfigDAL dal = new EtlSourceViewConfigDAL(loginInfo);
            return dal.RollBackSourceViewConfig(viewID, deleteSourceViewConfig);
        }
        #endregion
    }
}